<%@ page language="java" contentType="text/html; charset=windows-1255" pageEncoding="windows-1255"%>
<%@ include file="admin_Header.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="http://code.jquery.com/mobile/latest/jquery.mobile.min.css" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/latest/jquery.mobile.min.js"></script>
<title>Delete Supermarket</title>
</head>
<body>
<div data-role="page">
	<div data-role="header" align="center">
		<h1>Products Compare<br>Application</h1>
		
		<a href='#' class='ui-btn-left' data-icon='arrow-l' onclick="history.back(); return false">Back</a><a href="#admin_firstpage">Home</a>
	</div>
	
	<div data-role="footer" data-theme="b" align="center">
		<h2>Please Select Supermarket To Delete</h2>
	</div>
	
	<div data-role="content" align="center">
<%
	if (request.getParameter("supermarketId") != null)
	{
	    try
	    {
	    	Supermarket supermarket = iproducts.FindSupermarketById(Integer.valueOf(request.getParameter("supermarketId")));
	    	iproducts.DeleteSupermarket(supermarket);
	    }
	    catch (NumberFormatException e)
		{
		    throw new Exception("Parameter input error");
		}
	    catch (Exception e)
	    {
	        throw new Exception("Error in connecting to database, please contact your administrator");
		}
	}
	else
	{
		out.println("<form action=\"admin_DeleteSupermarket.jsp\">");
		try
		{
			List<Supermarket> supermarkets = iproducts.FindAllSupermarkets();
			out.println("<select name=\"supermarketId\" data-theme=\"e\">");
			for (Supermarket supermarket : supermarkets)
			{
				System.out.println("<option name=\"supermarketId\" value=\"" + supermarket.getSupermarketId() +"\"> " + supermarket.getSupermarketName() +"</option>");
				out.println("<option name=\"supermarketId\" value=\"" + supermarket.getSupermarketId() +"\"> " + supermarket.getSupermarketName() +"</option>");
			}
			out.println("</select>");
			out.println("<button type=\"submit\" data-theme=\"e\">Delete</button>");
			out.println("</form>");
		}
		catch (Exception e)
		{
		    throw new Exception("Error in connecting to database, please contact your administrator");
		}
	}
%>
	</div>
</div>
</body>
</html>